package com.lalameow.researchstation.util.serialization

import kotlinx.serialization.KSerializer
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import net.minecraft.text.Text

object TextAsJsonStringSerializer : KSerializer<Text> {
    override val descriptor = PrimitiveSerialDescriptor("Text", PrimitiveKind.STRING)

    override fun deserialize(decoder: Decoder) = Text.Serializer.fromJson(decoder.decodeString())!!

    override fun serialize(encoder: Encoder, value: Text) = encoder.encodeString(Text.Serializer.toJson(value))
}
